import{u as k,j as e,ci as w,cl as T,cm as C,cn as p,dv as S,cy as A,dw as F,bc as B,B as N,dx as f,bo as R,bp as g,ai as z,R as E}from"./ContentChatStore.thns9zdZ.js";import{r as y}from"./vendor.BaH-a-x7.js";const P=({annotations:c,onOpenSection:n,onRemoveAnnotation:m})=>{const[l,d]=y.useState(!1),{t:s}=k(),u=()=>{setTimeout(()=>{d(!1)},5e3)},j=a=>{navigator.clipboard.writeText(a),d(!0),u()},i=async a=>{await f.delete(a),m(a)};return e.jsxs("div",{className:"w-[600px] flex flex-col gap-3",id:"noteTable","data-note-container":"noteTable",children:[e.jsx(w,{"data-table":"container",children:e.jsx(T,{"data-table":"body",children:c&&c.length>0?c.map((a,h)=>e.jsxs(C,{children:[e.jsx(p,{children:e.jsx("p",{className:"text-center text-sm text-gray-700 dark:text-gray-300","data-table-item":"text",children:a.text})}),e.jsxs(p,{className:" flex-row gap-3",children:[e.jsx("p",{className:"text-center text-sm text-gray-700 dark:text-gray-300","data-table-item":"date",children:a.date}),e.jsx("p",{className:"text-center text-sm text-gray-700 dark:text-gray-300","data-table-item":"hour",children:a.hour})]}),e.jsx(p,{className:"flex-row items-end",children:e.jsxs("div",{className:"flex gap-2","data-table-actions":"container",children:[e.jsxs("button",{className:"text-gray-700 dark:text-gray-300 hover:text-blue-500 dark:hover:text-blue-500",onClick:()=>j(a.text),children:[e.jsx(S,{size:18,className:`${l?"hidden":""} text-current`}),e.jsx(A,{size:18,className:`${l?"":"hidden"} text-current`})]}),e.jsx("button",{className:"text-gray-700 dark:text-gray-300 hover:text-yellow-500 dark:hover:text-yellow-500",onClick:()=>n("form",{id:a.id,text:a.text}),children:e.jsx(F,{size:18,className:"text-current"})}),e.jsx("button",{className:"text-gray-700 dark:text-gray-300 hover:text-red-500 dark:hover:text-red-500",onClick:()=>i(a.id),children:e.jsx(B,{size:18,className:"text-current"})})]})})]},h)):e.jsx("div",{className:"w-full p-4 text-center text-gray-700 dark:text-gray-300 text-base border-[1px] border-dotted border-gray-700 dark:border-gray-300 rounded","data-note-container":"displayTableEmpty",children:s("contactProfile.alerts.emptyNotes")})})}),e.jsx("div",{className:"w-full mt-5 flex justify-center",children:e.jsx(N,{text:s("common.actions.create"),onClick:()=>n("form")})})]})},$=({contactId:c,defaultData:n,onOpenSection:m,onSaveAnnotation:l,onUpdateAnnotation:d})=>{const{t:s}=k(),u=i=>{i.preventDefault(),m("table")},j=async i=>{i.preventDefault();const h=[...i.target.querySelectorAll("[data-field]")],{id:b,text:o,method:t}=h.reduce((x,v)=>({...x,[v.dataset.field]:v.value}),{});if(!o){alert(s("contactProfile.alerts.insertTextToNotes"));return}const r={text:o};if(t==="create"){const x=await f.create(c,r);l(x)}else{const x=await f.update(b,r);d(x)}m("table")};return e.jsxs("div",{className:"w-full flex-col gap-3",id:"noteForm","data-note-container":"noteForm",children:[e.jsxs("h1",{className:"text-xl text-gray-700 dark:text-gray-300 font-bold",children:[s(n?"common.actions.edit":"common.actions.create")," ",s("contactProfile.notes.titleLowercase")]}),e.jsx(R,{onSubmit:j,children:e.jsxs(e.Fragment,{children:[e.jsxs(g,{children:[e.jsx("input",{type:"text",className:"hidden","data-field":"id",value:(n==null?void 0:n.id)??""}),e.jsx("input",{type:"text",className:"hidden","data-field":"method",value:n?"edit":"create"})]}),e.jsx(g,{children:e.jsx(z,{type:"text",placeholder:s("common.texts.addText"),"data-field":"text",defaultValue:(n==null?void 0:n.text)??""})}),e.jsx(g,{children:e.jsxs("div",{className:"w-full flex justify-center gap-3 mt-3",children:[e.jsx(N,{text:`${s(n?"common.actions.save":"common.actions.create")}`,className:"mx-0"}),e.jsx(N,{text:"Cancelar",className:"mx-0",onClick:u})]})})]})})]})},q=({contactId:c,closeModal:n,animationActv:m=!0})=>{const[{selectedSection:l,annotations:d},s]=y.useState({selectedSection:{section:"table"},annotations:[]}),{t:u}=k(),j=o=>{s(t=>({...t,annotations:[...t.annotations,o]}))},i=o=>{s(t=>({...t,annotations:t.annotations.filter(r=>r.id!==o)}))},a=o=>{s(t=>({...t,annotations:t.annotations.map(r=>r.id===o.id?o:r)}))},h=(o,t=null)=>{s(r=>({...r,selectedSection:{section:o,defaultData:t}}))};y.useEffect(()=>{(async()=>{const t=await f.list();s(r=>({...r,annotations:Object.values(t).filter(x=>x.contact===c)}))})()},[c]);const b=y.useMemo(()=>{const t={table:e.jsx(P,{annotations:d,onOpenSection:h,onRemoveAnnotation:i}),form:e.jsx($,{contactId:c,defaultData:l.defaultData,onOpenSection:h,onSaveAnnotation:j,onUpdateAnnotation:a})}[l.section];return t||null},[l,d,c]);return e.jsx(E,{onClose:n,animationActv:m,header:u("contactProfile.notes.title"),children:b})};export{q as default};
